<template>
  <view class="swiper-tab-box">
    <view class="swiper-tab">
      <scroll-view scroll-x="true" v-for="(item, index) in newList" :key="index" class="swiper-tab-list"
        :data-current="index" @click="swichNav" v-if="!(!openAppointment && index == 1)">
        <view class="item" :style="{color: currentTab == index || (!openAppointment && index == 2 && currentTab == 1) ? '#000' : '#c6c6c6'}">
          {{ item.name ? item.name : item }}
          <image v-if="currentTab == index || (!openAppointment && index == 2 && currentTab == 1)" class="item_active" :src="activeIconImg"></image>
          <block v-if="openAppointment">
            <view class="dot" v-if="item.dotNum > 0">{{ item.dotNum >= 100 ? '99+' : item.dotNum }}</view>
          </block>
          <block v-else>
            <block v-if="index > 1">
              <view class="dot" v-if="item.dotNum > 0">{{ item.dotNum >= 100 ? '99+' : item.dotNum }}</view>
            </block>
            <block v-else>
              <view class="dot" v-if="item.dotNum > 0">{{ item.dotNum >= 100 ? '99+' : item.dotNum }}</view>
            </block>
          </block>
        </view>
      </scroll-view>
    </view>
    <view class="swiper-tab-pd-line"></view>
  </view>
</template>
<script>
  export default {
    props: {
      currentTab: {
        default: 0
      },
      tabList: {
        type: Array
      }
    },
    data() {
      return {
        currentTabNew: this.currentTab,
        newList: this.tabList,
        openAppointment: this.$programSetting.openAppointment,
        activeIconImg: ""
      };
    },
    mounted(){
      const { orderTabActiveSvgImg } = require("./imgs.svg.js");
      this.activeIconImg = orderTabActiveSvgImg();
    },
    methods: {
      /**
       * 点击tab切换
       */
      /**
       * 头部红点标识
       * @param  {[type]} dotList [description]
       * @return {[type]}         [description]
       */
      changeList(dotList) {
        // this.tabList = dotList;
        this.newList = dotList;

      },
      swichNav(e) {
        let that = this;
        if (this.currentTabNew == e.currentTarget.dataset.current) {
          return false;
        } else {
          if (!that.openAppointment && e.currentTarget.dataset.current == 2) {
            that.currentTabNew = e.currentTarget.dataset.current;
            this.$emit('currentTab', that.currentTabNew - 1);
          } else {
            that.currentTabNew = e.currentTarget.dataset.current;
            this.$emit('currentTab', that.currentTabNew);
          }
        }
        // this.$emit('currentTab', that.currentTabNew);
      },
    },
    watch: {
      currentTab(newValue, oldValue) {
        
      }
    },
  }
</script>
<style lang="less">
  .swiper-tab-box{
    position: relative;
    width: 100%;
    height: 112rpx;
    background: #fff;
  }
  .swiper-tab-pd-line{
    width: 100%;
    height: 1px;
    background-color: #F2F2F2;
    position: absolute;
    left: 0;
    bottom: 4px;
    z-index: 1;
  }

  .dot {
    position: absolute;
    display: flex;
    width: 28rpx;
    height: 28rpx;
    line-height: 40rpx;
    text-align: center;
    align-items: center;
    justify-content: center;
    background: #CB171A;
    border-radius: 100%;
    color: #fff;
    z-index: 999;
    font-size: 16rpx;
    top: 30rpx;
    right: 0;
  }

  .dotbig {
    position: absolute;
    display: flex;
    width: 50rpx;
    height: 35rpx;
    line-height: 40rpx;
    text-align: center;
    align-items: center;
    justify-content: center;
    background: #e52424;
    border-radius: 100px;
    color: #fff;
    z-index: 999;
    font-size: 26rpx;
    top: 0;
    right: -10rpx;
  }

  .swiper-tab {
    width: 100%;
    padding: 0 48rpx;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
    text-align: center;
    line-height: 104rpx;
    height: 112rpx;
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
  }

  .swiper-tab-list {
    .item {
      position: relative;
      padding: 0 30rpx;
      color: #c6c6c6;
      font-size: 24rpx;
      font-weight: 500;
      text-align: center;
      font-family: NotoSansSC-Medium;
    }
    .item_active{
      width:28rpx;
      height: 14rpx;
      position: absolute;
      left: 50%;
      margin-left: -14rpx;
      bottom: -7rpx;
      z-index: 2;
    }
  }

  .active {
    color: #000;
    border-bottom: 5rpx solid #CB171A;
  }

  .swiper-box {
    display: block;
    height: 100%;
    width: 100%;
    overflow: hidden;
  }

  .swiper-item-box {
    overflow-y: scroll;
    overflow-x: hidden;
  }
</style>
